package com.imooc.socketexample;

import java.io.*;
import java.lang.reflect.Proxy;
import java.net.URISyntaxException;
import java.net.URL;

/**
 * Created by yijy on 2017/11/7.
 */
public class Test2 {

    public static void main(String[] args) {
        try {
            URL url = new URL("http://www.baidu.com");

            URL url1 = new URL("http://fanyi.baidu.com/translate?aldtype=16047&query=option&keyfrom=baidu&smartresult=dict&lang=auto2zh#en/zh/option");
            try {
                System.out.println(url1.toURI()+"\t"+url1.toURI().getAuthority());
            } catch (URISyntaxException e) {
                e.printStackTrace();
            }
            System.out.println(url.getAuthority());
            System.out.println(url.getContent()+";默认端口："+url.getDefaultPort());
            System.out.println(url.getHost()+";"+url.getPath());
            System.out.println(url.getPort());
            System.out.println(url.getProtocol());
//            InputStream is =url.openStream();
//            InputStreamReader isr = new InputStreamReader(is);
//            BufferedReader br = new BufferedReader(isr);
//            BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(new FileOutputStream("baidu.html") , "utf-8"));
//            while (br.readLine()!=null){
//                bw.write(br.readLine());
//            }
//            bw.flush();
//            bw.close();
//            br.close();
//            isr.close();
//            is.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
